import 'package:flutter/material.dart';
import 'package:fun4live/pages/homePage.dart';
import 'package:fun4live/pages/mainPageView.dart';
import 'package:get/get.dart';
import '../controller/constant.dart';

class homePageController extends GetxController{
  Rx<Color> color = Colors.blue.obs;
  var count = 0.obs;
  RxList<HomePageItem> items = RxList<HomePageItem>( []);
  var index = 0.obs;
    RxList<Widget> pages = RxList<Widget>([
    const SizedBox(),
    const SizedBox(),
    const SizedBox(),
    const SizedBox(),
  ]);


  Map<int , MaterialColor> colorSet = {0:Colors.pink,1:Colors.blue,2:Colors.red,3:Colors.yellow};
  int i =1;
  void switchColor()
  {
      i=i+1;
      i = (i)%4;
      print("i-$i,color:${colorSet[i]}");
      color.value = colorSet[i]??Colors.green;
      count++;
  }

  void setIndex(int i){
    print("setIndex:$i");
    if(pages.length <=i)
    {
      print("length:$pages.length,i:$i");
    }
    if(pages[i] is SizedBox)
    {
      switch( items[i].index)
      {
        case 0:
          //Get.put(homePageController());
          pages[i] = const mainPageView();
          break;
        case 1:
          pages[i] = const Text("flow user");
          break;
        case 2:
          pages[i] = const Text(" CategoryController");
          break;
        case 3:
          pages[i] = const Text("UserPage");
          break;
        default:
      }
    }
    else{

    }
    index.value = i;
  }
  @override
  void onInit() {
    // TODO: implement onInit
    //Future.delayed(Duration.zero, showFirstRun);
    //items.value = AppSettingsController.instance.homeSort
    //    .map((key) => Constant.allHomePages[key]!)
   //     .toList();
    items.value = Constant.allHomePages.values.toList();

    print("---onInit,\n");
    //print(items.value.toString());
   // setIndex(0);
    super.onInit();

  }
}